package org.example.text;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.TimeoutUtils;
import org.springframework.data.redis.core.ValueOperations;

import java.util.concurrent.TimeUnit;

/**
 * @Auther:Liu
 * @Testname:SpringText02
 * @Date:2025/8/11 16:50
 */
@Slf4j
@SpringBootTest
public class SpringText02 {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Test
    public void a()
    {
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        ops.set("A","a");
        ops.set("B","b");
        ops.set("C","c");
        ops.set("D","d");
        ops.setIfAbsent("A","a2");
        ops.setIfAbsent("E","e1");
        ops.setIfPresent("C","c2");
        ops.setIfPresent("F","f1");
    }

    @Test
    public void b()
    {
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        String a = ops.get("A");
        log.info("a:{}",a);
        String b = ops.getAndExpire("B",1, TimeUnit.HOURS);
        log.info("b:{}",b);
        String c = ops.getAndPersist("C");
        log.info("c:{}",c);
        String d = ops.getAndSet("D", "d2");
        log.info("d:{}",d);
        String e = ops.getAndDelete("E");
        log.info("e:{}",e);
    }

    @Test
    public void c()
    {
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        ops.append("A","a1236983");
        Long b = ops.size("B");
        log.info("b:{}",b);
        ops.set("Q","12");
        ops.increment("Q");
        ops.increment("Q",4);
        ops.decrement("Q");
        ops.decrement("Q",3);
    }
}
